<template>
  <el-form :model="increase" label-width="auto" style="max-width: 600px">
    <el-form-item label="图片地址">
      <el-input v-model="increase.img" />
    </el-form-item>
    <el-form-item label="图片链接">
      <el-input v-model="increase.link" />
    </el-form-item>
    <el-form-item label="图片提示">
      <el-input v-model="increase.alt" />
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="onSubmit">提交</el-button>
    </el-form-item>
  </el-form>
</template>

<script lang="ts" setup>
import { reactive } from "vue";
import { bannerpushapi } from "@/api/bannerin";
import { ElMessage } from "element-plus";
// do not use same name with ref
interface picture {
  img: string;
  alt: string;
  link: string;
}
const increase = reactive<Array<picture>>({
  img: "",
  link: "",
  alt: "",
});

const onSubmit = async () => {
  // console.log("submit!", increase);

  const res = await bannerpushapi(increase);
  if (res.data.code === "200") {
    ElMessage.success("添加成功了！");
  }
  clearbanner();
};
import { toRefs } from "vue";

function clearbanner() {
  const { img, link, alt } = toRefs(increase);
  img.value = "";
  link.value = "";
  alt.value = "";
}
</script>


<style>
</style>